﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Ylh.DBUtility;
using Ylh.IDAL;
using Ylh.Model;
using System.Data;
using System.Data.SqlClient;

namespace Ylh.SQLServerDAL
{
    public class ComRoleDAL : IComRole
    {
        /// <summary>
        /// 根据角色编号获取当前的角色信息
        /// </summary>
        /// <param name="ConStr"></param>
        /// <param name="RoleID">角色编号</param>
        /// <returns></returns>
        public DataTable GetCompetenceByRoleID(string ConStr, string RoleID)
        {
            string sql = "SELECT * FROM TbComRole where RoleID=" + RoleID;

            return SqlHelper.ExcuteQuery(ConStr, sql, CommandType.Text);
        }
        /// <summary>
        /// 根据角色编号删除角色权限
        /// </summary>
        /// <param name="ConStr"></param>
        /// <param name="RoleID">角色编号</param>
        /// <returns></returns>
        public bool DeleteComByRole(string ConStr, String RoleID)
        {
            string sql = @"delete TbComRole where RoleID=" + RoleID;

            int i = SqlHelper.ExecuteNonQuery(ConStr, sql, CommandType.Text);

            if (i > 0) return true;
            return false;
        }


        /// <summary>
        /// 插入权限关联
        /// </summary>
        /// <param name="ConStr"></param>
        /// <param name="RoleID"></param>
        /// <param name="ComID"></param>
        /// <returns></returns>
        public int InsertCom(string ConStr, string RoleID, string ComID)
        {
            string sql = @"INSERT INTO TbComRole (RoleID,CompetenceID,CreateTime)
VALUES(@RoleID,@CompetenceID,getdate())";
            SqlParameter[] pre = new SqlParameter[] 
            {
              new SqlParameter ("@RoleID",RoleID),
               new SqlParameter ("@CompetenceID",ComID)
             };
            return SqlHelper.ExecuteNonQuery(ConStr, sql, pre, CommandType.Text);
        }






    }
}
